package characterstream;

import java.io.*;

public class InputStreamReaderDemo {

    public static void main(String[] args) {
        BufferedReader bin = null;
        BufferedWriter bout = null;

        File srcFile = new File("D:" + File.separator + "MyUtils.java");
        File destFile = new File("E:" + File.separator + "MyUtils.java");
        try {
            //因为是字节流转字符流有可能出现中文乱码，必须指定正确的字符编码格式。
            bin = new BufferedReader(new InputStreamReader(new FileInputStream(srcFile), "utf-8"));
            bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destFile), "utf-8"));

            long startTime = System.currentTimeMillis();
            String s = null;
            while ((s = bin.readLine()) != null) {
                bout.write(s + "\r\n");
            }

            long endTime = System.currentTimeMillis();
            System.out.println("总用时：" + (endTime - startTime) + "毫秒");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (bin != null) {
                    bin.close();
                    bin = null;
                }
                if (bout != null) {
                    bout.close();
                    bout = null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
